﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.CollectionsUI {
    import flash.display.*;
    import org.aswing.*;
    import Classes.*;
    import com.greensock.*;
    import flash.filters.*;
    import org.aswing.geom.*;
    import Display.*;
    import Display.MarketUI.*;
    import Display.aswingui.*;

    public class CollectionItemCell extends DataItemCell {

        protected var m_itemIconPane:JPanel;
        protected var m_countPane:JPanel;
        protected var m_countLabel:JTextField;
        protected var m_slotSize:IntDimension;
        protected var m_slotOffset:int;
        protected var m_initialized:Boolean = false;
        protected var m_fadeInOnInit:Boolean = false;
        protected var m_completeCallback:Function = null;
        protected var m_initializedCallback:Function = null;
        protected var m_fadeTween:TweenLite = null;
        private var m_count:int = 0;

        public function CollectionItemCell(_arg1:LayoutManager=null, _arg2:IntDimension=null, _arg3:int=2){
            super(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, 0, SoftBoxLayout.CENTER));
            if (_arg2){
                this.m_slotSize = _arg2;
            } else {
                this.m_slotSize = new IntDimension(Catalog.CARD_WIDTH, Catalog.CARD_HEIGHT);
            };
            this.m_slotOffset = _arg3;
            setPreferredSize(this.m_slotSize);
        }
        override protected function scaleToFit(_arg1:DisplayObject):Number{
            var _local2:Number = 1;
            var _local3:Number = 1;
            var _local4:int = (this.m_slotSize.width - this.m_slotOffset);
            var _local5:int = (this.m_slotSize.height - this.m_slotOffset);
            if (_arg1.width > _local5){
                _local2 = (_local5 / _arg1.width);
            };
            if (_arg1.height > _local4){
                _local3 = (_local4 / _arg1.height);
            };
            return (Math.min(_local2, _local3));
        }
        override protected function initializeCell():void{
            this.m_count = Global.player.getNumCollectablesOwned(m_item.name);
            this.createCell();
            m_itemIcon.alpha = this.getItemAlpha(this.m_count);
        }
        protected function createCell():void{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(AsWingConstants.CENTER, -15);
            this.m_itemIconPane = ASwingHelper.makeSoftBoxJPanelVertical();
            var _local2:AssetPane = new AssetPane(m_itemIcon);
            ASwingHelper.prepare(_local2);
            this.m_itemIconPane.append(_local2);
            ASwingHelper.prepare(this.m_itemIconPane);
            this.createCountLabel(_local1, this.m_count);
            _local1.append(this.m_itemIconPane);
            ASwingHelper.prepare(_local1);
            this.append(_local1);
            ASwingHelper.prepare(this);
            if (((this.m_fadeInOnInit) && (!((this.m_completeCallback == null))))){
                this.fadeInTween(this.m_completeCallback);
            };
            this.m_initialized = true;
            if (this.m_initializedCallback != null){
                this.m_initializedCallback(true);
            };
        }
        protected function getItemAlpha(_arg1:int):Number{
            if ((((_arg1 == 0)) || (this.m_fadeInOnInit))){
                return (0);
            };
            return (1);
        }
        public function invalidateData():void{
            if (this.m_initialized){
                this.m_count = Global.player.getNumCollectablesOwned(m_item.name);
                this.m_countLabel.setText((("x" + this.m_count) + " "));
                ASwingHelper.prepare(this);
            };
        }
        public function playFadeIn(_arg1:Function, _arg2:Function):void{
            if (this.m_fadeTween != null){
                _arg1();
                return;
            };
            if (this.m_initialized){
                _arg2(true);
                this.m_initializedCallback = null;
                this.fadeInTween(_arg1);
            } else {
                _arg2(false);
                this.m_initializedCallback = _arg2;
                this.m_fadeInOnInit = true;
                this.m_completeCallback = _arg1;
            };
        }
        protected function fadeInTween(_arg1:Function):void{
            this.m_fadeTween = TweenLite.to(m_itemIcon, 1, {
                alpha:1,
                onComplete:_arg1
            });
        }
        public function forceFadeComplete():void{
            if (((((this.m_fadeInOnInit) && (this.m_completeCallback))) && (!(this.m_initialized)))){
                this.m_completeCallback();
            };
        }
        protected function createCountLabel(_arg1:JPanel, _arg2:int=0):void{
            this.m_countPane = ASwingHelper.makeSoftBoxJPanel(AsWingConstants.LEFT);
            this.m_countLabel = ASwingHelper.makeTextField((("x" + _arg2) + " "), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, 0xFFFFFF);
            this.m_countLabel.filters = [new GlowFilter(0)];
            this.m_countPane.append(ASwingHelper.horizontalStrut(30));
            this.m_countPane.append(this.m_countLabel);
            ASwingHelper.prepare(this.m_countPane);
            _arg1.append(this.m_countPane);
        }

    }
}//package Display.CollectionsUI 
